/**
 * 2013，thor.com，all rights reserved。
 * 
 * Project：		thor-common
 * Filename：	QueryOrder.java
 * Created：		2013-11-11
 * Creator：		thor
 */
package com.jeecg.query;

import java.io.Serializable;

/**
 * @author thor
 *
 */
public class QueryOrder implements Serializable {
  private static final long serialVersionUID = 2909448806549120342L;

  /** 升序 */
  public static final QueryOrderDirection ASC = QueryOrderDirection.asc;
  /** 降序 */
  public static final QueryOrderDirection DESC = QueryOrderDirection.desc;

  public QueryOrder() {
    // Do Nothing
  }

  public QueryOrder(String field) {
    this(field, ASC);
  }

  public QueryOrder(String field, QueryOrderDirection direction) {
    setField(field);
    setDirection(direction);
  }

  private String field;
  private QueryOrderDirection direction = QueryOrderDirection.asc;

  public String getField() {
    return field;
  }

  public void setField(String field) {
    this.field = field;
  }

  public QueryOrderDirection getDirection() {
    return direction;
  }

  public void setDirection(QueryOrderDirection direction) {
    this.direction = direction;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((direction == null) ? 0 : direction.hashCode());
    result = prime * result + ((field == null) ? 0 : field.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    QueryOrder other = (QueryOrder) obj;
    if (direction != other.direction)
      return false;
    if (field == null) {
      if (other.field != null)
        return false;
    } else if (!field.equals(other.field))
      return false;
    return true;
  }

}
